package com.example.photo.config;

import com.example.photo.filter.TokenFilter;
import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.StringJoiner;

/**
 * 过滤器配置类
 *
 * @author Lwh
 * @time 2023/03/26 22:11
 */
@Configuration
public class FilterConfig {
    @Bean
    FilterRegistrationBean<TokenFilter> tokenFilterFilterRegistrationBean() {
        FilterRegistrationBean<TokenFilter> filterBean = new FilterRegistrationBean<>();
        filterBean.setFilter(new TokenFilter());
        filterBean.setOrder(1);
        filterBean.addUrlPatterns("/*");
        // 排除的路径
        StringJoiner exPath = new StringJoiner(",");
        exPath.add("/user/register/common")
                .add("/user/login/common")
                .add("/user/login/tju")
                .add("/user/verify")
                .add("/user/reset")
                .add("/user/send")
                .add("/file/upload")
                .add("/file/get");
        filterBean.addInitParameter("excludedURIs", String.valueOf(exPath));
        return filterBean;
    }
}
